package com.pw.canbuslogger;

import java.util.Calendar;
import java.util.Queue;
import java.util.Random;

public class CANBusDataReader implements Runnable {

    private final Queue<Object[]> queue;
    private final Random random;

    public CANBusDataReader(Queue<Object[]> queue) {
        this.queue = queue;
        this.random = new Random(3);
    }

    @Override
    public void run() {
        while (true) {
            Object[] record = new Object[11];
            record[CANBusRecordFields.ID] = random.nextInt(10);
            record[CANBusRecordFields.LEN] = (byte) random.nextInt(4);
            record[CANBusRecordFields.BYTE01] = (byte) random.nextInt(4);
            record[CANBusRecordFields.BYTE02] = (byte) random.nextInt(4);
            record[CANBusRecordFields.BYTE03] = (byte) random.nextInt(4);
            record[CANBusRecordFields.BYTE04] = (byte) random.nextInt(4);
            record[CANBusRecordFields.BYTE05] = (byte) random.nextInt(4);
            record[CANBusRecordFields.BYTE06] = (byte) random.nextInt(4);
            record[CANBusRecordFields.BYTE07] = (byte) random.nextInt(4);
            record[CANBusRecordFields.BYTE08] = (byte) random.nextInt(4);
            record[CANBusRecordFields.TIME] = Calendar.getInstance();
            queue.offer(record);
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

    }

}
